package cn.aib.orderservice.service.impl;

import cn.aib.commonutils.vo.OrderNoUtil;
import cn.aib.orderservice.entity.Order;
import cn.aib.orderservice.mapper.OrderMapper;
import cn.aib.orderservice.service.OrderService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 订单 服务实现类
 * </p>
 *
 * @author testjava
 * @since 2021-01-23
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {

    @Override
    public String createOrder(Order order) {
        //生成订单号
        String orderNo = OrderNoUtil.getOrderNo();

        //补充信息
        order.setOrderNo(orderNo);
        order.setStatus(0);

        baseMapper.insert(order);

        return orderNo;
    }

    @Override
    public Order getOrderInfo(String orderNum) {
        //根据订单号查询订单信息
        QueryWrapper<Order> wrapper = new QueryWrapper<>();

        wrapper.eq("order_no", orderNum);

        Order order = baseMapper.selectOne(wrapper);

        return order;
    }
}
